package wang.hu.bos.service.transit.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import wang.hu.bos.dao.WayBillDao;
import wang.hu.bos.dao.index.WayBillIndexDao;
import wang.hu.bos.dao.transit.TransitDao;
import wang.hu.bos.domain.take_delivery.WayBill;
import wang.hu.bos.domain.transit.TransitInfo;
import wang.hu.bos.service.transit.TransitService;

@Service
@Transactional
public class TransitServiceImpl implements TransitService {

	@Autowired
	private TransitDao transitDao;
	@Autowired
	private WayBillDao wayBillDao;
	@Autowired
	private WayBillIndexDao wayBillIndexDao;

	@Override
	public void save(String wayBillIds) {
		for (String id : wayBillIds.split(",")) {
			WayBill wayBill = wayBillDao.findOne(Integer.parseInt(id));
			if (wayBill != null && wayBill.getSignStatus() == 1) {
				TransitInfo transitInfo = new TransitInfo();
				transitInfo.setWayBill(wayBill);
				transitInfo.setStatus("出入库中转");
				transitDao.save(transitInfo);
				wayBill.setSignStatus(2);
				wayBillIndexDao.save(wayBill);
			}
		}
	}

	@Override
	public Page<TransitInfo> pageData(Pageable pageable) {
		return transitDao.findAll(pageable);
	}

}
